<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\command\ocean;

use app\command\BaseWork;
use app\service\fetch\OceanFetchService;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;

class RebateMaterialWork extends BaseWork
{
    protected function configure()
    {
        // 指令配置
        $this->setName('oe_rebate_material_work');
        // 设置参数
        $this->setDescription('拉取低质素材');

        // 设置参数
        $this->addArgument('agent_id', Argument::OPTIONAL, '代理商id')
            ->addArgument('month', Argument::OPTIONAL, '月份')
            ->setHelp('php think oe_rebate_material_work [agent_id] [month]');
    }

    protected function execute(Input $input, Output $output)
    {
        set_time_limit(0);
        $agentId = strval($input->getArgument('agent_id') ?: '1721840200150023');
        $month = strval($input->getArgument('month') ?: date('Y-m'));
        $this->getOutputMessage('拉取低质素材[' . $agentId . ']开始');
        try {
            $res = OceanFetchService::fetchRebateMaterialList($agentId, $month);
            if (! $res) {
                $this->getOutputMessage('拉取低质素材[' . $agentId . ']失败:' . OceanFetchService::getError(0));
            }
        } catch (\Exception $e) {
            $this->getOutputMessage('拉取低质素材[' . $agentId . ']失败:' . $e->getMessage());
        }

        $this->getOutputMessage('拉取低质素材结束');
    }

}
